<template>
  <div class="app-container">
    <div class="order_stat">
      <div class="title">
        <span>提现审核</span>
        <div class="com-export-dialog">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:good:export']"
            >批量导出</el-button
          >
          <!-- <el-button type="primary" size="mini" @click="handleAdd">批量审核</el-button>
                    <el-button type="primary" size="mini">批量打款</el-button> -->
        </div>
      </div>
      <div class="stat_details">
        <div class="order_module" v-for="item in order_module" :key="item.id">
          <div class="oirder_modul_title">
            <div>{{ item.name }}</div>
            <!-- <el-tooltip class="item" effect="dark" :content="item.toolip" placement="bottom">
                            <i class="el-icon-question" style="color: #afadad;margin-left: 3px;font-size: 17px;"></i>
                        </el-tooltip> -->
          </div>
          <div class="price">
            {{ item.num }}
          </div>
        </div>
      </div>
    </div>
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="0">

            <el-form-item label="" prop="userId">
                <el-input v-model="queryParams.userId" placeholder="请输入会员id" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="" prop="nickName">
                <el-input v-model="queryParams.nickName" placeholder="请输入昵称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="" prop="userPhone">
                <el-input v-model="queryParams.userPhone" placeholder="请输入手机号" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="" prop="goodId">
                <el-select clearable v-model="checkboxList" placeholder="请选择提现方式" style="width:100%">
                    <el-option v-for="item in 4" :key="item" :value="item">{{ item }}</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="" prop="goodId">
                <el-select clearable v-model="checkboxList" placeholder="请选择提现类型" style="width:100%">
                    <el-option v-for="item in 3" :key="item" :value="item">{{ item }}</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="">
                <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                    range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="selectTimeChange"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form> -->

    <el-tabs v-model="queryParams.status" @tab-click="handleClick">
      <el-tab-pane label="全部" name="0"></el-tab-pane>
      <!-- <el-tab-pane label="未审核" name="second"></el-tab-pane> -->
      <!-- <el-tab-pane label="待打款" name="third">
                <el-button type="primary" size="mini">支付宝批量</el-button>
            </el-tab-pane> -->
      <el-tab-pane
        :label="item.name"
        :name="`${item.value}`"
        v-for="item in statusList"
        :key="item.value"
      ></el-tab-pane>
    </el-tabs>

    <!-- <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['system:good:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['system:good:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                    @click="handleDelete" v-hasPermi="['system:good:remove']">删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['system:good:export']">批量导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row> -->

    <el-table
      v-loading="loading"
      :data="goodList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="orderId" />
      <el-table-column label="会员ID" align="center" prop="sysUserid" />
      <el-table-column label="提现账号名称" align="center" prop="name" />
      <el-table-column label="提现账号" align="center" prop="accountNumber" />
      <!-- <el-table-column label="基本信息" align="center" prop="deptName" /> -->
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="{ row }">
          {{ row.mode == "1" ? "支付宝" : "银行卡" }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="账户信息" align="center" prop="classifyImg" /> -->
      <!-- <el-table-column label="提现方式" align="center" prop="way">
        <template slot-scope="{ row }">
          {{ row.way == "1" ? "直接提现" : "入余额" }}
        </template>
      </el-table-column> -->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="{ row }">
          {{ forrmatterEnmu(statusList, row.status) }}
        </template>
      </el-table-column>
      <el-table-column label="时间" align="center" prop="createTime">
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            :disabled="scope.row.status != 1"
            @click="handleCheck(scope.row, 1)"
            v-hasPermi="['system:good:edit']"
            >通过</el-button
          >
          <el-button
            size="mini"
            type="text"
            :disabled="scope.row.status != 1"
            @click="handleCheck(scope.row)"
            v-hasPermi="['system:good:remove']"
            >驳回</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改供应商商品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="操作" prop="goodId">
          <el-radio-group v-model="radio" size="small">
            <el-radio label="1" border>同意</el-radio>
            <el-radio label="2" border>拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="deptName">
          <el-input v-model="form.deptName" placeholder="备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  goodClassifyList,
  goodClassifyDetail,
  goodclassifyAdd,
  goodclassifyEdit,
  goodclassifyDelete,
} from "@/api/system/goods/classify";
import {
  recordList,
  recordId,
  recordExport,
  systemRecord,
  recordAudit,
  recordDelete,
  withdrawStatistics,
} from "@/api/assets/withdrawal";
import { forrmatterEnmu } from "@/utils/index";
import { status } from "nprogress";

export default {
  name: "Good",
  data() {
    return {
      order_module: [
        { name: "待审核总佣金", num: 0 },
        { name: "待打款总佣金", num: 0 },
        { name: "已打款总佣金", num: 0 },
        { name: "已驳回总佣金", num: 0 },
        { name: "平台总佣金", num: 0 },
      ],
      radio: "1",
      checkboxList: "",
      activeName: "first",
      // 日期范围
      dateRange: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商商品表格数据
      goodList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: "0",
        deptName: null,
        sort: null,
        classifyImg: null,
        delFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        productLevel: [
          {
            required: true,
            message: "商品等级 1vip 3共享店主 4联创 5区域运营 6总裁不能为空",
            trigger: "blur",
          },
        ],
      },
      statusList: [
        {
          name: "申请中",
          value: 1,
        },
        {
          name: "审核通过",
          value: 2,
        },
        {
          name: "已打款",
          value: 3,
        },
        {
          name: "驳回",
          value: 4,
        },
        {
          name: "打款异常",
          value: 5,
        },
      ],
    };
  },
  created() {
    this.getList();
    this.getStatistics();
  },
  methods: {
    forrmatterEnmu,
    handleClick(tab, event) {
      console.log(tab, event);
      this.getList();
    },

    getStatistics() {
      withdrawStatistics(this.queryParams).then((response) => {
        this.order_module[0].num = response.data.pendingApprovalTotalCommission;
        this.order_module[1].num = response.data.pendingPaymentTotalCommission;
        this.order_module[2].num = response.data.paidTotalCommission;
        this.order_module[3].num = response.data.rejectedTotalCommission;
        this.order_module[4].num = response.data.platformTotalCommission;
      });
    },
    /** 查询供应商商品列表 */
    getList() {
      this.loading = true;
      // this.addDateRange(this.queryParams, this.dateRange)
      recordList(this.queryParams).then((response) => {
        this.goodList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deptName: null,
        sort: null,
        classifyImg: null,
        status: null,
        delFlag: null,
      };
      this.dateRange = [];
      this.resetForm("form");
    },
    uploadImg(v) {
      this.form.classifyImg = v;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "批量审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      goodClassifyDetail(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商品分类";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.status = this.form.status ? "0" : "1";
          this.form.delFlag = this.form.delFlag ? "0" : "1";
          if (this.form.id != null) {
            goodclassifyEdit(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            goodclassifyAdd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除数据？")
        .then(function () {
          return goodclassifyDelete(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/system/record/export",
        {
          ...this.queryParams,
        },
        `good_${new Date().getTime()}.xlsx`
      );
    },
    handleCheck(row, type) {
      let data = {
        id: row.id,
        status: type ? 2 : 4,
      };
      recordAudit(data).then((res) => {
        this.$message.success("审核成功");
        this.getList();
      });
    },
  },
};
</script>
<style lang="less" scoped>
.app-container {
  width: 100%;
  height: 1005;
  background-color: #fff;

  .order_stat {
    background: #fff;
    padding: 10px 10px 0;
    margin-bottom: 10px;

    .title {
      font-size: 18px;
      font-weight: bold;
      display: flex;
      align-items: center;
      height: 40px;
      display: flex;
      justify-content: space-between;
    }

    .stat_details {
      padding: 30px 0;
      display: flex;

      .order_module {
        flex: 1;
        background: #f2f2f2;
        margin: 0 5px;
        padding: 20px 25px;

        .oirder_modul_title {
          font-size: 12px;
          margin-bottom: 10px;
          display: flex;
          align-items: center;
          color: #46a6ff;
        }

        .price {
          font-size: 22px;
          font-weight: bold;
        }
      }
    }
  }
}
</style>
